package com.yangrd.airship.upms.infrastructure;

import com.yangrd.airship.common.UserInfo;
import com.yangrd.airship.common.UserInfoService;
import com.yangrd.airship.upms.domain.UserRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * @author yangrd
 * @date 2021/11/26
 */
@RequiredArgsConstructor

@Component
public class SimpleUserInfoService implements UserInfoService {

    private final UserRepository repository;

    @Override
    public Optional<UserInfo> loadUser(Integer userId) {
        return repository.findById(userId).map(user -> UserInfo.of(user.getId(),user.getUsername()));
    }
}
